package cn.xny.basic.controller;


import cn.xny.basic.dto.PhoneCodeDto;
import cn.xny.basic.exception.BusinessException;
import cn.xny.basic.service.VerifyCodeService;
import cn.xny.basic.util.AjaxResult;
import cn.xny.basic.util.BaiduAuditUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifyCode")
public class verifyCodeController {


    @Autowired
    private VerifyCodeService verifyCodeService;

    //获取图形验证码
    @GetMapping("/image/{key}")
    public AjaxResult getImageCode(@PathVariable("key") String key){

        try {
             String  base64str  = verifyCodeService.getImageCode(key);
           return AjaxResult.me().setObj(base64str);
        } catch (Exception e) {
            e.printStackTrace();

           return new AjaxResult(false,e.getMessage());
        }

    }
    //获取手机验证码
    @PostMapping("/phone")
    public AjaxResult getPhoneCode(@RequestBody PhoneCodeDto phoneCodeDto){

        try {
              verifyCodeService.getPhoneCode(phoneCodeDto);

            return AjaxResult.me();
        } catch ( BusinessException e) {
            e.printStackTrace();

            return new AjaxResult(false,e.getMessage());
        }catch ( Exception e) {
            e.printStackTrace();

            return new AjaxResult(false,"系统繁忙，稍后重试");
        }

    }
    //获取手机验证码
    @PostMapping("/binderSmsCode")
    public AjaxResult getBinderSmsCode(@RequestBody PhoneCodeDto phoneCodeDto){

        try {
            verifyCodeService.getBinderSmsCode(phoneCodeDto);

            return AjaxResult.me();
        } catch ( BusinessException e) {
            e.printStackTrace();

            return new AjaxResult(false,e.getMessage());
        }catch ( Exception e) {
            e.printStackTrace();

            return new AjaxResult(false,"系统繁忙，稍后重试");
        }

    }
}
